<template>
  <el-table
    :header-row-style="headerRowStyle"
    :cell-style="cellStyle"
    :data="tableData"
    style="width: 100%"
    border>
    <el-table-column v-bind:label="title0+title1" style="border: black">
      <el-table-column prop="t1" label="排查对象" align="center" min-width="15%"></el-table-column>
      <el-table-column prop="t2" label="停机原因" align="center" min-width="35%"></el-table-column>
      <el-table-column prop="t3" label="出现概率" align="center" min-width="10%"></el-table-column>
      <el-table-column prop="t4" label="排查方法" align="center" min-width="40%"></el-table-column>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  name: 'FaultAnalysis',
  data () {
    return {
      // 上个页面传输数据
      type: '',
      id: '',
      result: [],
      // 表格标题
      title: '',
      title0: '',
      title1: '  故障情况分析',
      // 表格数据
      tableData: [
        {
          t1: '1',
          t2: '',
          t3: '',
          t4: ''
        },
        {
          t1: '2',
          t2: '',
          t3: '',
          t4: ''
        },
        {
          t1: '3',
          t2: '',
          t3: '',
          t4: ''
        },
        {
          t1: '4',
          t2: '',
          t3: '',
          t4: ''
        },
        {
          t1: '5',
          t2: '',
          t3: '',
          t4: ''
        },
        {
          t1: '6',
          t2: '',
          t3: '',
          t4: ''
        }
      ],
      // 状态评价参数
      state_plus: [],
      state_sum: '',
      // 无序百分比数组
      state_per: [],
      // 有序百分比数组
      state_ord: [],
      order0: [],
      paichaQiege: ['无需排查', '大车齿轮', '对角线', '划线枪', '风门', '防撞圈'],
      reaQiege: ['切割机状态正常', '大车抖动', '对角线偏差', '划线不好', '吸尘无吸力', '防撞圈坏'],
      methodQiege: ['无需采取措施', '更换大车齿轮', '调整对角线', '更换电磁阀', '将风门完全打开', '防撞圈整形，更换限位'],
      paichaHanji: ['无需排查', '焊机电路连接线', '电源模块', '传感器', '焊机电路连接线', '保险管'],
      reaHanji: ['焊机状态正常', '机内断线', '电源缺相', '传感器损坏', '线间短路', '机内保险管断'],
      methodHanji: ['无需采取措施', '1', '2', '3', '4', '5']
    }
  },
  methods: {
    // 表头格式
    headerRowStyle ({row, column, rowIndex, columnIndex}) {
      if (rowIndex === 0) {
        return 'height: 90px; color: #dc2323; font-size: 20px'
      } else if (rowIndex === 1) {
        return 'height: 70px; color: black; font-size: 16px'
      }
    },
    // 单元格格式
    cellStyle ({row, column, rowIndex, columnIndex}) {
      if (rowIndex === 0) {
        if (columnIndex === 2) {
          return 'height: 70px; color: #f32020; font-family: 黑体; font-size: 20px'
        } else if (columnIndex === 0) {
          return 'height: 70px; color: black; font-family: 黑体; font-size: 20px'
        } else {
          return 'height: 70px; color: black; font-size: 16px'
        }
      } else {
        if (columnIndex === 2) {
          return 'height: 70px; color: #f32020; font-family: 黑体; font-size: 20px'
        } else if (columnIndex === 0) {
          return 'height: 70px; color: black; font-family: 黑体; font-size: 20px'
        } else {
          return 'height: 70px; color: black; font-size: 16px'
        }
      }
    },
    timer () {
      return setInterval(() => {
      }, 100)
    },
    getParams () {
      const routeParams = this.$route.query
      this.type = routeParams.equip
      this.id = routeParams.num
      this.result = routeParams.res
    },
    showTitle () {
      if (this.type === 'qiegeji') {
        this.title0 = '切割机' + this.id
      } else {
        this.title0 = '自动焊机' + this.id
      }
      this.title = this.title0 + this.title1
    },
    showData () {
      if (this.type === 'qiegeji') {
        this.state_sum = 0
        for (var k = 0; k < 6; k++) {
          var t10 = Number(700)
          var t11 = Number(this.result[k])
          this.state_plus[k] = t10 + t11
          var t12 = Number(this.state_plus[k])
          this.state_sum += t12
        }
        for (var l = 0; l < 6; l++) {
          var t13 = Number(this.state_plus[l])
          var t14 = Number(this.state_sum)
          this.state_per[l] = t13 / t14 * 100
        }
        this.desOrder(this.state_per, 6)
        this.showQiegeji(this.state_per)
      } else if (this.type === 'hanji') {
        this.state_sum = 0
        for (var i = 0; i < 6; i++) {
          var t0 = Number(700)
          var t1 = Number(this.result[i])
          this.state_plus[i] = t0 + t1
          var t2 = Number(this.state_plus[i])
          this.state_sum += t2
        }
        for (var j = 0; j < 6; j++) {
          var t3 = Number(this.state_plus[j])
          var t4 = Number(this.state_sum)
          this.state_per[j] = t3 / t4 * 100
        }
        this.desOrder(this.state_per, 6)
        this.showHanji(this.state_per)
      }
    },
    showHanji (shuzu) {
      for (var i = 0; i < 6; i++) {
        var s = shuzu[i].toString()
        this.state_ord[i] = s.substring(0, s.indexOf('.') + 3) + '%'
      }
      for (var j = 0; j < 6; j++) {
        this.tableData[j].t1 = this.paichaHanji[Number(this.order0[j])]
        this.tableData[j].t2 = this.reaHanji[Number(this.order0[j])]
        this.tableData[j].t3 = this.state_ord[j]
        this.tableData[j].t4 = this.methodHanji[Number(this.order0[j])]
      }
    },
    showQiegeji (shuzu) {
      for (var i = 0; i < 6; i++) {
        var s = shuzu[i].toString()
        this.state_ord[i] = s.substring(0, s.indexOf('.') + 3) + '%'
      }
      for (var j = 0; j < 6; j++) {
        this.tableData[j].t1 = this.paichaQiege[Number(this.order0[j])]
        this.tableData[j].t2 = this.reaQiege[Number(this.order0[j])]
        this.tableData[j].t3 = this.state_ord[j]
        this.tableData[j].t4 = this.methodQiege[Number(this.order0[j])]
      }
    },
    changePos (arr, cur, right) {
      var tmp
      tmp = arr[cur]
      arr[cur] = arr[right]
      arr[right] = tmp
    },
    desOrder (arr, sz) {
      this.order0 = [0, 1, 2, 3, 4, 5]
      for (var i = 0; i < sz - 1; i++) {
        var end = i
        var tmp = arr[end + 1]
        while (end >= 0) {
          if (arr[end] < tmp) {
            this.changePos(arr, end, end + 1)
            this.changePos(this.order0, end, end + 1)
            end--
          } else {
            break
          }
        }
      }
    }
  },
  created () {
    this.getParams()
    this.showTitle()
    this.showData()
  }
}
</script>

<style scoped>
.el-table{
  color: #dc2323;
}
.e-title {
  color: #f32020;
}
</style>
